package cn.com.dcsgo.controller;

import cn.com.dcsgo.domain.Prod;
import cn.com.dcsgo.dto.PageDTO;
import cn.com.dcsgo.model.Result;
import cn.com.dcsgo.service.MemberCollectionService;
import cn.com.dcsgo.utils.AuthUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 会员收藏相关接口
 *
 * @author Dcsgo
 * @since 2025/10/30 17:49
 */
@Tag(name = "会员收藏相关接口")
@RestController
@RequestMapping("p/collection")
public class CollectionController {
    @Resource
    private MemberCollectionService memberCollectionService;

    @GetMapping("count")
    @Operation(summary = "获取收藏商品数")
    public Result<Long> getCollectionCount() {
        return Result.success(memberCollectionService.getCollectionCount());
    }

    @GetMapping("prods")
    @Operation(summary = "分页获取收藏商品信息")
    public Result<Page<Prod>> getCollectProd(PageDTO pageDTO) {
        return Result.success(memberCollectionService.getCollectProd(pageDTO));
    }

    @GetMapping("isCollection")
    @Operation(summary = "商品是否收藏")
    public Result<Boolean> isCollected(@RequestParam("prodId") Long prodId) {
        return Result.success(memberCollectionService.isCollected(AuthUtil.getOpenid(), prodId));
    }

    @GetMapping("addOrCancel")
    @Operation(summary = "收藏或取消收藏商品")
    public Result<Void> addOrCancel(@RequestParam("prodId") Long prodId) {
        return Result.handle(memberCollectionService.addOrCancel(AuthUtil.getOpenid(), prodId));
    }
}
